package cn.wit.db.web;

import cn.wit.db.entity.AjaxResult;
import cn.wit.db.entity.Department;
import cn.wit.db.mapper.DepartmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class DepartmentController {
    @Autowired
    DepartmentMapper mapper;

    //查询
    @GetMapping("/department")
    public List<Department> getDepartment(){
       return mapper.selectAll();
    }

    //插入
    @PostMapping("/department")
    public AjaxResult createDepartment(@RequestBody Department department){
         mapper.insert(department);
         return AjaxResult.success();
    }

    //删除
    @DeleteMapping("/department")
    public AjaxResult deleteDepartment(@PathVariable Department department){
         mapper.deleteByPrimaryKey(department.getDno());
         return AjaxResult.success();
    }

    //修改
    @PutMapping("/department")
    public AjaxResult updateDepatment(@PathVariable Department department){
         mapper.updateByPrimaryKey(department);
         return AjaxResult.success();
    }
}
